package com.cheetah.service.impl;

import com.cheetah.config.UserServerConfig;
import com.cheetah.dto.LoginDTO;
import com.cheetah.dto.UserDTO;
import com.cheetah.service.LoginOutService;
import com.cheetah.session.SessionManager;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author Administrator
 * @Date 2019/9/19
 * @Version V1.0
 * @Description:
 **/
@Service
public class LoginOutServiceImpl implements LoginOutService {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private SessionManager sessionManager;

    @Autowired
    private UserServerConfig userServerConfig;

    @Override
    public UserDTO login(LoginDTO loginDTO, Channel channel){
        UserDTO userDTO = restTemplate.postForObject(userServerConfig.getUrl() + "/user/login",loginDTO,UserDTO.class);
        sessionManager.login(userDTO.getUserId(),channel);
        return userDTO;
    }
}
